package easymall.controller;

import easymall.po.Category;
import easymall.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/getCategorysByPage")
    public List<Category> getCategorysByPage(@RequestParam Integer page){
        return categoryService.getCategorysByPage(page);
    }

    @GetMapping("/getTotalPage")
    public int getTotalPage(){
        return categoryService.getTotalPage();
    }

    @GetMapping("/allcategorys")
    public List<Category> allcategorys(){
        return categoryService.allcategorys();
    }

    @GetMapping("/getCategorysCount")
    public int getCategorysCount(){
        return categoryService.getCategorysCount();
    }

    @GetMapping("/checkCategorysExist")
    public int checkCategorysExist(@RequestParam String name) {
        return categoryService.checkCategorysExist(name);
    }

    @PostMapping("/updateCategory")
    public int updateCategory(@RequestBody Category category) {
        return categoryService.updateCategory(category);
    }

    @GetMapping("/saveCategory")
    public int saveCategory(@RequestParam String name){
        return categoryService.saveCategory(name);
    }

    @GetMapping("/delCategory")
    public int delCategory(@RequestParam Integer id){
        return categoryService.delCategory(id);
    }
}
